const DotenvWebpackPlugin = require("dotenv-webpack");
const { config: configDotEnv } = require("dotenv");
const path = require("path");
// const { DefinePlugin, ProvidePlugin } = require("webpack");

const dotConfig = configDotEnv({
  path: path.resolve(__dirname, `./env/.env.${process.env.NODE_ENV}`),
});

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  experimental: {
    // appDir: true,

    // serverComponentsExternalPackages: ['react', 'react-dom'],
    serverMinification: false,
  },
  webpack: (config, { isServer }) => {
    // if (!isServer) {
    // }

    // config.plugins.push(new DotenvWebpackPlugin({ path: "./.env" }));

    // config.plugins.push(
    //   new ProvidePlugin({
    //     process: "global.process",
    //   })
    //   // new DefinePlugin({
    //   //   "process.env": `(${JSON.stringify(dotConfig.parsed)})`,
    //   // })
    // );

    config.plugins.push(
      new DotenvWebpackPlugin({
        path: `./env/.env.${process.env.NODE_ENV}`,
        prefix: "import.meta.env.",
      })
    );

    // console.log("🚀 ~ dotConfig.parsed:", dotConfig.parsed);

    return config;
  },
};

module.exports = nextConfig;
